{template 'header'}
<link href="./resource/css/app.css" rel="stylesheet">
<ul class="nav nav-tabs">
    <li class="active"><a href="javascript:;">任务管理</a></li>
<li class=""><a href="{php echo $this->createWebUrl('task', array('op' => 'addshow'))}">添加任务</a></li>
</ul>
<form action="./index.php" method="get" class="form-horizontal">
    <input type="hidden" name="c" value="site">
    <input type="hidden" name="a" value="entry">
    <input type="hidden" name="m" value="bh_rising">
    <input type="hidden" name="do" value="task">
</form>
<div class="panel panel-default">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:80px;">标题</th>
                <th style="width:70px;">类型</th>
                <th style="width:70px;">次数/时间</th>
                <th style="width:70px;">金币</th>
                <th style="width:70px;">顺序</th>
                <th style="width:70px;">点击量</th>
                <th style="width:70px;">时间</th>
                <th style="width:80px;">操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $task['list'] $item}
            <tr>
                <td>{$item['title']}</td>
                <td>{php echo $item['type'] ==1 ? '观看激励视频': '试玩其他小程序'}</td>
                <td>{$item['number']}</td>
                <td>{$item['currency']}</td>
                <td><input type="text" value="{$item['sort']}" class="sort" style="width: 30px;" data-id="{$item['id']}"></td>
                <td><a href="{php echo $this->createWeburl('taskClick', array( 'id' => $item['id']));}" target="_blank">{$item['clickNumber']}</a></td>
                <td>{php echo date('Y-m-d H:i:s',$item['created'])}</td>
               <td>
                    <a class="btn btn-success  btn-sm" href="{php echo $this->createWeburl('task', array('op' => 'editshow', 'id' => $item['id']));}">编辑</a>
                    <a href="javascript:;" class="delete btn btn-warning  btn-sm" data-id="{$item['id']}">删除</a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
    </div>
    {$task['pages']}
</div>
<script type="application/javascript">
    $(function () {
        $('.delete').click(function () {
            if (!confirm('确认要删除该任务')) {
                return false;
            }
            id = $(this).data('id');
            $.post('', {id:id, op:'delete'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });

        $('.sort').blur(function () {
            var sort = $(this).val();
            var  id = $(this).data('id');
            $.post('', {id:id,sort:sort, op:'sort'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('排序失败');
                }

            }, 'json')
        });

    });

</script>